<?php

use Biz\model\salesRebate\SalesAccount as mSalesAccount;
use Biz\service\salesRebate\SalesRebate as sSalesRebate;
use Doraemon\tools\HhzClient;

class GetOrderAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;
    const PAGE_SIZE = 30;

    public function main()
    {
        $uid = $this->uid;
        $page = $this->getRequest()->getPost('page', '');
        $page = $page ? $page : 1;
        $status = $this->getRequest()->getPost('status', '');

        $where = [
            'uid' => $uid,
            'ORDER' => ['id' => 'DESC'],
            'LIMIT' => [($page - 1) * self::PAGE_SIZE, self::PAGE_SIZE],
        ];
        if ($status <> '') {
            $where['status'] = $status;
        }
        if (in_array(HhzClient::getClientType(), [HhzClient::APPTYPE_IOS, HhzClient::APPTYPE_ANDROID])) {
            unset($where['status']);
            $where['type'] = mSalesAccount::TYPE_APP;
            $result = sSalesRebate::getAppSaleOrder($where, $page, self::PAGE_SIZE);
        } else {
            $result = sSalesRebate::getOrder($where, $page, self::PAGE_SIZE);
        }


        $this->setSuccess($result);
    }

}